<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="/favicon.ico">
    <title>注册 -- 佩奇说说</title>
    <!-- Bootstrap core CSS -->
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/jumbotron.css" rel="stylesheet">
    <style>
        body {
            padding-top: 120px;
        }
        #error{
            display: none;
        }
    </style>
  </head>

  <body>

    <% include header.ejs %>
    <div class="container">
      <!-- Example row of columns -->
      <div class="row col-lg-6">
          <h1>欢迎注册</h1>
        <form>
            <div class="form-group">
                <label for="Username">用户名</label>
                <input type="text" class="form-control" id="Username" placeholder="用户名，可以是中文，不能与别人重复">
            </div>
            <div class="form-group">
                <label for="Password">密码</label>
                <input type="password" class="form-control" id="Password" placeholder="密码，至少六位">
            </div>
            <div class="checkbox">
                <label>
                <input type="checkbox"> 我遵守注册规定
                </label>
            </div>
            <button type="button" id="regist" class="btn btn-default">提交</button>
        </form>

        <div class="alert alert-danger" role="alert" id="error">
            用户名被占用，请更换
        </div>
      </div>
      <hr>

      <footer>
        <p>&copy; 2016 Company, Inc.</p>
      </footer>
    </div> <!-- /container -->

    <script src="js/jquery-1.11.3.min.js"></script>
    <script>window.jQuery || document.write('<script src="/js/vendor/jquery.min.js"><\/script>')</script>
    <script src="/js/bootstrap.min.js"></script>
    <script type="text/javascript">
        $("input").focus(function(){                // 失去焦点的时候去掉错误框
            $("#error").fadeOut();
        })
        $("#regist").click(function(){
            $.post("/doregist",{
            "username" : $("#Username").val(),
            "password" : $("#Password").val()
            },function(result){
                if(result == "1"){
                    alert("注册成功！将自动返回首页");
                    window.location ="/";
                }else if (result == "-1"){      // 用户名被占用
                    $("#error").fadeIn();
                    $("#error").html("用户名被占用啊");
                }else if(result == "-3"){

                }
            });
        });
    </script>
  </body>
</html>
